home *** CD-ROM | disk | FTP | other *** search
/ Click - International Series 1 / Click Jigsaw Puzzles: Ken Duncan.iso / mac / puzzles / Tranquility.dxr / 00225_import image & make puzzle.ls < prev    next >
Encoding:
Text File  |  2002-11-11  |  6.7 KB  |  186 lines

  1. global allTogether, fit, piecesParts, allPieces, totalPieces, tolerance, stageWide, stageTall, saved, completePreviewLoc, start, puzzShape, puzzPicFile, puzzCrop, currentPuzzle, puzzShading, puzzFolder, stageStart, puzzleRect, totalSteps, puzzpicrotation, puzzleImageRect, zoomScale, difficulty, previewSprite
  2.  
  3. on abortPuzzle
  4.   cursor(4)
  5.   thisSprite = 2
  6.   repeat while thisSprite <= 160
  7.     set the puppet of sprite thisSprite to 0
  8.     sprite(thisSprite).visible = 1
  9.     thisSprite = 1 + thisSprite
  10.   end repeat
  11.   initPuzzler()
  12.   cursor(0)
  13.   abort()
  14. end
  15.  
  16. on stopPuzzle
  17.   cursor(4)
  18.   thisSprite = 2
  19.   repeat while thisSprite <= 160
  20.     set the puppet of sprite thisSprite to 0
  21.     sprite(thisSprite).visible = 1
  22.     thisSprite = 1 + thisSprite
  23.   end repeat
  24.   updateStage()
  25.   resetPreview()
  26. end
  27.  
  28. on slicedice
  29.   cursor(4)
  30.   totalSteps = 100
  31.   eachStep = 100 / float(totalPieces)
  32.   firstMask = the number of member (string(puzzShape) & totalPieces) - 1
  33.   thisMember = 1
  34.   repeat while thisMember <= totalPieces
  35.     erase(member(thisMember))
  36.     thisMember = 1 + thisMember
  37.   end repeat
  38.   thisMember = 1
  39.   repeat while thisMember <= totalPieces
  40.     new(#bitmap, member(thisMember))
  41.     thisMember = 1 + thisMember
  42.   end repeat
  43.   progressStep = 244 / float(totalPieces)
  44.   thisPiece = 1
  45.   repeat while thisPiece <= totalPieces
  46.     member("puzzpic" & string(puzzShape)).duplicate(thisPiece)
  47.     member(thisPiece).name = EMPTY
  48.     member(thisPiece).image.copyPixels(member(firstMask + thisPiece).image, member("puzzpic" & string(puzzShape)).rect, member("puzzpic" & string(puzzShape)).rect, [#color: 0, #ink: 1])
  49.     member(thisPiece).image = member(thisPiece).image.trimWhiteSpace()
  50.     sprite(263).width = max(1, progressStep * thisPiece)
  51.     updateStage()
  52.     thisPiece = 1 + thisPiece
  53.   end repeat
  54.   updateStage()
  55.   return 1
  56. end
  57.  
  58. on getPreviewRect
  59.   cursor(0)
  60.   cursor(4)
  61.   puzzWide = member(221).width
  62.   puzzTall = member(221).height
  63.   if (puzzWide / float(puzzTall)) >= (4 / 3.0) then
  64.     previewTall = 180
  65.     previewWide = 180 / float(puzzTall) * puzzWide
  66.   else
  67.     previewWide = 240
  68.     previewTall = 240 / float(puzzWide) * puzzTall
  69.   end if
  70.   previewLeft = 0
  71.   previewRight = previewWide
  72.   previewTop = 0
  73.   previewBottom = previewTall
  74.   return rect(previewLeft, previewTop, previewRight, previewBottom)
  75.   cursor(0)
  76. end
  77.  
  78. on makeSavedPuzzle changeDifficulty
  79.   cursor(4)
  80.   progressDialog()
  81.   thisSprite = 2
  82.   repeat while thisSprite <= 221
  83.     sprite(thisSprite).visible = 0
  84.     thisSprite = 1 + thisSprite
  85.   end repeat
  86.   thisSprite = previewSprite - 5
  87.   repeat while thisSprite <= previewSprite
  88.     sprite(thisSprite).visible = 0
  89.     thisSprite = 1 + thisSprite
  90.   end repeat
  91.   updateStage()
  92.   case the runMode of
  93.     "projector":
  94.       setupInfo = getPuzzleFileIO(getOSDirectory() & currentPuzzle & ".txt")
  95.     "author":
  96.       setupInfo = getPuzzleFileIO(getOSDirectory() & currentPuzzle & ".txt")
  97.     "plugin":
  98.       setupInfo = getPref(currentPuzzle & ".txt")
  99.   end case
  100.   if not voidp(setupInfo) and not changeDifficulty then
  101.     the itemDelimiter = TAB
  102.     difficulty = value(item 11 of setupInfo)
  103.   end if
  104.   puzzShape = value("#" & word 1 of the name of member 221)
  105.   if changeDifficulty then
  106.     totalPieces = value(word difficulty + 1 of the name of member 221)
  107.   else
  108.     if voidp(difficulty) then
  109.       difficulty = 2
  110.     end if
  111.     if voidp(totalPieces) then
  112.       totalPieces = value(word difficulty + 1 of the name of member 221)
  113.     end if
  114.   end if
  115.   newPicRect = member(string(puzzShape) & string(totalPieces)).rect
  116.   newPic = new(#bitmap, member(1))
  117.   picBlank = image(newPicRect[3], newPicRect[4], 32)
  118.   picBlank.fill(0, 0, newPicRect[3], newPicRect[4], rgb(255, 0, 0))
  119.   member(1).image = picBlank
  120.   member(1).image.copyPixels(member(221).image, member(string(puzzShape) & totalPieces).rect, member(221).rect)
  121.   member("complete" & string(puzzShape)).media = member(1).media
  122.   makePuzzpic()
  123.   member("puzzpic" & string(puzzShape)).image = member(1).image
  124.   makePreview()
  125.   member(totalPieces + 1).media = member(1).media
  126.   member(totalPieces + 1).name = "preview"
  127.   if slicedice(0) then
  128.     cursor(4)
  129.     thisSprite = 2
  130.     repeat while thisSprite <= 221
  131.       set the puppet of sprite thisSprite to 0
  132.       set the ink of sprite thisSprite to 8
  133.       thisSprite = 1 + thisSprite
  134.     end repeat
  135.     sprite(1).visible = 1
  136.     updateStage()
  137.     go("initpuzzle")
  138.     set the stageColor to the stageColor
  139.     puzzPicFile = EMPTY
  140.     cursor(0)
  141.   end if
  142.   member(totalPieces + 2).media = member("complete" & string(puzzShape)).media
  143.   member(totalPieces + 2).name = "complete"
  144.   member(totalPieces + 3).media = member("allTogether" & string(puzzShape) & string(totalPieces)).media
  145.   member(totalPieces + 3).name = "allTogether"
  146.   member(totalPieces + 4).media = member("puzzleLayout" & string(puzzShape) & string(totalPieces)).media
  147.   member(totalPieces + 4).name = "puzzleLayout"
  148.   thisSprite = 220
  149.   repeat while thisSprite <= 221
  150.     sprite(thisSprite).visible = 1
  151.     thisSprite = 1 + thisSprite
  152.   end repeat
  153.   clearDialog()
  154. end
  155.  
  156. on makePreview
  157.   previewRect = getPreviewRect()
  158.   newPreview = new(#bitmap, member(1))
  159.   previewBlank = image(previewRect[3], previewRect[4], 32)
  160.   previewBlank.fill(0, 0, previewRect[3], previewRect[4], rgb(255, 0, 0))
  161.   member(1).image = previewBlank
  162.   member(1).image.copyPixels(member("complete" & string(puzzShape)).image, member(1).rect, member("complete" & string(puzzShape)).rect)
  163.   member(1).regPoint = point(member(1).width / 2, member(1).height / 2)
  164. end
  165.  
  166. on makePuzzpic
  167.   newPuzzpic = member("complete" & string(puzzShape)).duplicate(1)
  168.   member(1).name = EMPTY
  169.   member(1).image.copyPixels(member("hilite" & string(puzzShape) & totalPieces).image, member(1).rect, member(1).rect, [#ink: 33])
  170.   member(1).image.copyPixels(member("shadow" & string(puzzShape) & totalPieces).image, member(1).rect, member(1).rect, [#ink: 35])
  171.   member(1).image.copyPixels(member("complete" & string(puzzShape)).image, member(1).rect, member(1).rect, [#blend: 60, #ink: 32])
  172.   member(1).image.copyPixels(member("offWhiteMatte" & string(puzzShape) & totalPieces).image, member(1).rect, member(1).rect, [#ink: 39])
  173. end
  174.  
  175. on setDifficulty
  176.   difficulties = member(221).name.word[2] && "Pieces" & RETURN & member(221).name.word[3] && "Pieces" & RETURN & member(221).name.word[4] && "Pieces"
  177.   put difficulties into member "difficulties"
  178.   member("jigsawMenu acdefghjkln").image.copyPixels(member("difficulties").image, rect(17, 144, 92, 193), rect(0, 0, 75, 48), [#ink: 0])
  179.   member("jigsawMenu adefghjkln").image.copyPixels(member("difficulties").image, rect(17, 144, 92, 193), rect(0, 0, 75, 48), [#ink: 0])
  180. end
  181.  
  182. on clearDifficulty
  183.   member("jigsawMenu acdefghjkln").image.fill(17, 144, 92, 193, rgb(238, 238, 238))
  184.   member("jigsawMenu adefghjkln").image.fill(17, 144, 92, 193, rgb(238, 238, 238))
  185. end
  186.